#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import sys

conf_dict={}
with open(sys.argv[1]) as conf_file:
    for line in conf_file:
        if len(line.strip("\n").split("\001"))!=4:
            continue
        cid,sid,ctid,t=line.strip("\n").split("\001")
        t=str(int(float(t.strip())))
        k=cid.strip()+sid.strip()
        conf_dict[k]=[t,ctid]

def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        pass

    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass

    return False


for data in sys.stdin:
    if len(data.strip("\n").split("\t"))!=5:
        continue
    cid,sid,session,nasid,dtime=data.strip("\n").split("\t")
    if not dtime or dtime =="NULL" or not session or not is_number(dtime):
        continue
    d=int(float(dtime.strip()))
    k=cid.strip()+sid.strip()
    if k in conf_dict and int(conf_dict[k][0]) <= d:
        print cid+"\t"+sid+"\t"+nasid+"\t"+conf_dict[k][1]+"\t"+conf_dict[k][0]+"\t"+"1"